<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\models\UserConfig;
use yii\helpers\Html;
use yii\helpers\Url;

/**
 * @var $this yii\web\View
 * @var $user app\models\User
 */

ApiAsset::register($this);
LayerAsset::register($this);

$this->title = '配置用户';
$this->params['breadcrumbs'][] = '用户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('', 'post', ['class' => 'form form-inline']);?>
<div class="form-group required">
    <label class="control-label" for="prepaid_postpaid">付费方式</label>
    <?php echo Html::radioList('prepaid_postpaid', UserConfig::getConfig($user->id, 'prepaid_postpaid'), ['prepaid' => '预付费', 'postpaid' => '后付费'], ['id' => 'prepaid_postpaid']);?>
    <div class="help-block"></div>
    <button type="button" onclick="saveUserConfig(<?php echo $user->id;?>, 'prepaid_postpaid', $('[name=prepaid_postpaid]:checked').val())" class="btn btn-sm btn-success">保存</button>
</div>
<?php echo Html::endForm();?>
<script>
    function saveUserConfig(uid, k, v) {
        $.getJSON('<?php echo Url::to(['/admin/user/save-user-config']);?>', {uid: uid, k: k, v: v}, function (json) {
            if (callback(json)) {
                layer.msg('数据已保存。');
            }
        });
    }
</script>
